home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Orlando_1993 / Devcon93.4 / CAMD / examples / trans / clamp.a < prev    next >
Encoding:
Text File  |  1992-12-31  |  1.5 KB  |  56 lines

  1. ******* util.lib/clamp ************************************************
  2. *
  3. *   NAME
  4. *       clamp -- constrain a longword between two values
  5. *
  6. *   SYNOPSIS
  7. *       newval = clamp( minval, val, maxval )
  8. *       D0              d0      d1   d2
  9. *
  10. *       LONG __asm clamp( register __D0 LONG, register __D1 LONG,
  11. *                         register __d2 LONG );
  12. *
  13. *   FUNCTION
  14. *       This function takes a longword input, and forces it to be between
  15. *       to values. If it is lower than the minimum value, then the minimum
  16. *       value is returned. If it is higher than the maximum value, then
  17. *       the maximum value is returned. Otherwise, the original value is
  18. *       returned.
  19. *
  20. *       If the minimum value is higher than the maximum, then the maximum
  21. *       value is always returned.
  22. *
  23. *   INPUTS
  24. *       minval      - the lower bound of the constraint
  25. *       val         - the value to be limited
  26. *       maxval      - the upper bound of the constraint
  27. *
  28. *   RESULT
  29. *       newval      - the constrained value
  30. *
  31. *   EXAMPLE
  32. *
  33. *   NOTES
  34. *       Like other things, this might be better as an inline function.
  35. *
  36. *   BUGS
  37. *
  38. *   SEE ALSO
  39. *
  40. *****************************************************************************
  41. *    Written by Talin
  42. *
  43.             SECTION text,CODE
  44.  
  45.             xdef        _clamp
  46.  
  47. _clamp:     cmp.l       d0,d1           ; find the higher of d0 and d1
  48.             blt.s       1$
  49.             move.l      d1,d0
  50. 1$          cmp.l       d0,d2           ; find the lower of d2 and d0
  51.             bgt.s       2$
  52.             move.l      d2,d0
  53. 2$          rts
  54.  
  55.             end
  56.